home *** CD-ROM | disk | FTP | other *** search
/ Aminet 44 / Aminet 44 (2001)(GTI - Schatztruhe)[!][Aug 2001].iso / Aminet / dev / debug / Wipeout.lha / Wipeout.doc < prev   
Text File  |  2001-02-10  |  24KB  |  554 lines

  1. Wipeout -- Traces and munges memory and detects memory trashing
  2.  
  3. Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  4. Public Domain
  5.  
  6. ------------------------------------------------------------------------------
  7.  
  8. 1. What is it?
  9.  
  10. Wipeout is a tool to watch and manipulate how memory is being put to use by
  11. the Amiga. By "put to use" I mean allocation, deallocation, invalid attempts
  12. to do either, forgetting to do either and memory trashing in general. In the
  13. right hands, Wipeout can be used to improve the quality of Amiga software by
  14. pointing into the direction of where a memory use problem might have
  15. originated.
  16.    Wipeout works best if used together with tools like Enforcer, SegTracker,
  17. Memoration, Scratch and tnt (these five are all part of the Software Toolkit,
  18. as distributed in the 3.1 Native Developer Kit or on the Amiga Developer CD
  19. v1.1). Wipeout does not work with MungWall; it is meant to be an alternative
  20. to MungWall.
  21.    Wipeout is related to the MemWall, MemMung and MungWall tools, but unlike
  22. these offers more and different functionality. The most prominent feature of
  23. Wipeout is its ability to track and watch memory pools; MungWall and its kin
  24. did not support this.
  25.  
  26.  
  27. 2. Requirements
  28.  
  29. Wipeout requires an Amiga equipped with Kickstart 2.04 or better. Aside from
  30. the operating system version, there are no special requirements.
  31.  
  32. Since Wipeout sends its output to the built-in Amiga serial port or the
  33. parallel port, you should either have a terminal or a printer connected to
  34. your machine, or you should run a program like Sashimi or Sushi to capture its
  35. output.
  36.  
  37.  
  38. 3. What Wipeout does
  39.  
  40.  1) Except when The Enforcer is running, memory location 0 is set to
  41.     0xC0DEDBAD; programs referencing location zero will not find a NULL
  42.     string.
  43.  
  44.  2) On startup all still unallocated (i.e. "free") memory is munged with
  45.     0xABADCAFE. If this number shows up, a program is referencing memory
  46.     in the free list.
  47.  
  48.  3) Except when MEMF_CLEAR is set as a memory allocation attribute,
  49.     freshly-allocated memory is pre-munged with 0xDEADF00D. When this is used
  50.     in an Enforcer report, the caller is allocating memory and does not
  51.     initialize it before using it.
  52.  
  53.  4) Memory is filled with 0xDEADBEEF before it is freed, encouraging programs
  54.     reusing freed memory to crash. See the configuration options REUSE and
  55.     NOREUSE for more information on this subject.
  56.  
  57.  5) Since memory allocations may not be done from within interrupt code,
  58.     all such attempts will be made to fail.
  59.  
  60.  6) Calling AllocMem()/AllocVec()/AllocPooled() with a zero length parameter
  61.     or NULL pool header will be made to fail.
  62.  
  63.  7) Calling FreeMem()/FreePooled() with a zero length parameter or a NULL
  64.     memory pointer/pool header will be registered as an error.
  65.  
  66.  8) Every memory deallocation must start on a long-word boundary (i.e. the
  67.     address to deallocate from must be a multiple of four); if it does not,
  68.     it will be registered as an error.
  69.  
  70.  9) Every memory deallocation should operate only on allocated memory and
  71.     should not overlap with unallocated memory; if this happens, it will be
  72.     registered as an error. Note that it is halfway legal to partly deallocate
  73.     memory. However, Wipeout does not tolerate such behaviour.
  74.  
  75. 10) Every memory deallocation has to match the size of the original
  76.     allocation; if it does not, it will be registered as an error.
  77.  
  78. 11) If memory is to be deallocated by a routine different from the one it was
  79.     allocated with (e.g. AllocVec() followed by FreePooled()), it will be
  80.     registered as an error.
  81.  
  82. 12) If memory following or preceding the allocation is trashed, it will be
  83.     reported.
  84.  
  85. 13) If a memory pool is created with the threshold size greater than the
  86.     puddle size, it will be reported.
  87.  
  88. 14) As memory pools may not be used by more than a single task at the same
  89.     time, any attempt to do so will be reported. In any event, Wipeout will
  90.     make sure that pool accesses are properly synchronized.
  91.  
  92. 15) Trying to deallocate memory from the wrong pool will be reported as an
  93.     error.
  94.  
  95. 16) Trying to deallocate memory from a pool if that memory has already been
  96.     deallocated will be reported as an error.
  97.  
  98. 17) If a memory allocation error is detected, the memory in question will not
  99.     be deallocated.
  100.  
  101. 18) Upon returning from a memory allocation routine, Wipeout will make sure
  102.     that all scratch registers (D1/A0/A1) will be scratched. These registers
  103.     will be set to the values D1=0xD100DEAD, A0=0xA000DEAD and A1=0xA100DEAD.
  104.  
  105. 19) Supposedly orphaned memory will be reported; see below for an explanation
  106.     of orphaned memory.
  107.  
  108.  
  109. 4. How memory is being watched
  110.  
  111. Wipeout places a magic cookie before each memory allocation. Along with a wall
  112. of bytes on either side of the allocation to keep an eye on the memory just
  113. before or after the allocation. If the memory wall is trashed, Wipeout
  114. complains and shows the damaged area. If memory is trashed so bad that the
  115. cookie is completely gone, Wipeout will not consider it a walled memory
  116. allocation and lets it go. Changes are you will be corrupting the memory list
  117. and/or overwriting other memory allocation and crash soon after that.
  118.  
  119.  
  120. 5. Interaction with other programs
  121.  
  122. Wipeout needs to know the caller's return address in order to determine the
  123. name of the program that tried to allocate/deallocate memory and where the
  124. operating system call came from. Thus, if you want to run other debugging
  125. tools that redirect calls to the memory management routines, you must make
  126. sure that Wipeout will be the last program to be started.
  127.  
  128. For optimum functionality, start the SegTracker tool before Wipeout is
  129. launched. And once Wipeout is running, proceed to run Enforcer.
  130.  
  131.  
  132. 6. Command line options
  133.  
  134. Wipeout can be started only from Shell.
  135.  
  136.  ********************************************
  137.  *                                          *
  138.  * TAKE GREAT CARE when running Wipeout for *
  139.  * the   first   time   since,  other  than *
  140.  * MungWall, Wipeout cannot be told to quit *
  141.  *                                          *
  142.  ********************************************
  143.  
  144. If Wipeout is started for the first time, it will plant its patches in the
  145. operating system, modify memory location zero, munge the currently unallocated
  146. memory and wait for something to happen. I recommend to always run Wipeout
  147. in the background, like this:
  148.  
  149.    run >nil: Wipeout
  150.  
  151. Every other attempt to start Wipeout will only cause the running Wipeout
  152. configuration to be updated.
  153.  
  154. The following command line options are available:
  155.  
  156. PRESIZE=number     This sets the number of bytes to place in front of each
  157.                    allocation; minimum is 8 bytes, maximum 65536 bytes,
  158.                    default is 32 bytes. The size will be rounded to be a
  159.                    multiple of eight bytes.
  160.  
  161. POSTSIZE=number    This sets the number of bytes to place behind each
  162.                    allocation; minimum is 8 bytes, maximum 65536 bytes,
  163.                    default is 32 bytes. The size will be rounded to be a
  164.                    multiple of eight bytes.
  165.  
  166. FILLCHAR=number    The character to fill the memory walls with. This can
  167.                    be given either in decimal or in hexadecimal notation.
  168.                    Default is a rolling fill character which uses a new
  169.                    odd number between 0x81 and 0xFF for each new allocation.
  170.                    This makes it possible for Wipeout to usually catch
  171.                    errors where too much memory is copied from one
  172.                    allocation to another. Specifying a FILLCHAR disables
  173.                    the default rolling fill character feature.
  174.  
  175. PARALLEL           This option activates parallel port output; default is
  176.                    serial port output through kprintf().
  177.  
  178. NOBANNER           This option will cause Wipeout not to print its banner
  179.                    message when it is started.
  180.  
  181. REMUNGE            Use this option to tell Wipeout to munge all unallocated
  182.                    memory again. You might want to use this periodically
  183.                    since deallocated memory will continue to clear out the
  184.                    regular free memory munge pattern over time, making it
  185.                    less likely for badly-written software to trip over
  186.                    unallocated memory.
  187.  
  188. CHECK              This tells Wipeout to check all known memory allocations
  189.                    for defects and to report damages, orphaned memory
  190.                    and the list of programs being monitored.
  191.  
  192. MARK               These options are for setting and clearing memory marks.
  193. UNMARK             A mark is used in conjunction with the SHOWUNMARKED
  194.                    option which will collect and display all so far unmarked
  195.                    memory allocations. Marks can help you tell older from
  196.                    newer memory allocations.
  197.  
  198. SHOWUNMARKED       This tells Wipeout to collect and display all so far
  199.                    unmarked memory allocations. Every memory allocation
  200.                    starts out as being unmarked. Thus, telling Wipeout to
  201.                    mark all allocations, waiting a bit and then using
  202.                    the SHOWUNMARKED option will display all allocations
  203.                    done since the time you set the marks. Note that this
  204.                    option really makes sense only if you did mark any
  205.                    memory before as you will otherwise see every
  206.                    active memory allocation (but then again, this might
  207.                    be just what you wanted to see...).
  208.  
  209. TASK=name          Watch only the task(s) or all but the task(s) specified
  210.                    with the "name" parameter. Multiple task names are
  211.                    indicated by placing a "|" between the names. If the names
  212.                    are preceeded by an exclamation mark ("!"), all tasks
  213.                    except for the ones indicated are tracked. "ALL" is a
  214.                    reserved name, indicating all tasks should be tracked;
  215.                    default is "ALL".
  216.  
  217.                    When names are compared, case does not matter. What names
  218.                    are compared against the contents of the list depends upon
  219.                    the type of the task whose name should be tested. If the
  220.                    task is truly a plain Task or Process, its task node name
  221.                    will be compared. If the task is in fact a Shell process
  222.                    with a program executing in it, then the name will be
  223.                    the name of that program.
  224.  
  225.                    Note that for a Shell program, the name will include the
  226.                    complete path name the program was started with. To find
  227.                    out which names the Shell programs are using, try the
  228.                    Shell "Status" command.
  229.  
  230. NAMETAG            These options control whether each memory allocation will
  231. NONAMETAG          be tagged with the name of the allocating task's or
  232.                    command's name and origin of the call. This will eat up
  233.                    extra memory and take extra time to store, so it is not
  234.                    enabled by default. If you wish to look for memory leaks
  235.                    in your software, use the NAMETAG option as it will
  236.                    provide information on the creator of an orphaned memory
  237.                    allocation until after the creator has already exited.
  238.                    Default is NONAMETAG.
  239.  
  240. ACTIVE             These options control whether Wipeout should track and
  241. INACTIVE           test memory usage; default is ACTIVE. While Wipeout is
  242.                    inactive, memory deallocations will still be tracked, but
  243.                    deallocation errors will not be reported.
  244.  
  245. WAIT               These options control whether each task to cause a
  246. NOWAIT             Wipeout hit will be halted and wait for a [Ctrl]-C
  247.                    break signal. Make sure that you can actually send
  248.                    that signal to the task in question. Default is NOWAIT.
  249.  
  250. CONSISTENCECHECK   These options control whether Wipeout will run a
  251. NOCONSISTENCECHECK consistency check on all its memory tracking data
  252.                    structures before performing memory deallocations and
  253.                    tracked allocations. This test may slow down the operation
  254.                    of the Amiga, especially on already very slow machines.
  255.                    Still, it is required to assure proper operation of the
  256.                    program; without consistent data structures, Wipeout will
  257.                    crash or fail to perform correctly.
  258.                    Default is NOCONSISTENCECHECK.
  259.  
  260. REUSE              It is semi-legal to continue using memory after releasing
  261. NOREUSE            it through FreeMem(), etc. while you are still in Forbid()
  262.                    state. Wipeout will by default tolerate such behaviour
  263.                    (default is REUSE), but you can also make it reject this
  264.                    through the NOREUSE option. TAKE GREAT CARE WHEN USING THE
  265.                    NOREUSE OPTION as -- unfortunately -- a great number of
  266.                    programs will break if it is in effect.
  267.  
  268. SHOWFAIL           These options control whether every failed memory
  269. NOSHOWFAIL         allocation will be reported; default is NOSHOWFAIL.
  270.  
  271. AREGCHECK          These options tell Wipeout that you wish all the values
  272. NOAREGCHECK        in the address registers to be checked via SegTracker;
  273.                    default is NOAREGCHECK.
  274.  
  275. DREGCHECK          These options tell Wipeout that you wish all the values
  276. NODREGCHECK        in the data registers to be checked via SegTracker;
  277.                    default is NODREGCHECK.
  278.  
  279. STACKCHECK         These options tell Wipeout that you wish all the values
  280. NOSTACKCHECK       displayed in the stack to be checked against the
  281.                    global segment lists via SegTracker. This will tell
  282.                    you in what segment lists various return addresses on
  283.                    the stack are found, which may help in tracing the
  284.                    location of an offending command. Default is NOSTACKCHECK.
  285.  
  286. STACKLINES=number  This option lets you pick the number of lines of stack
  287.                    backtrace to display. The default is 2. If set to 0,
  288.                    no stack backtrace will be displayed. There is NO ENFORCED
  289.                    LIMIT on the number of lines.
  290.  
  291. CHECKDELAY=number  This option selects how much time has to pass between
  292.                    two automatic memory checks. A check works similar to an
  293.                    test initiated with the CHECK option. The delay is given
  294.                    in 1/10th of a second, a value of 0 disables the automatic
  295.                    tests. Default is 0.
  296.  
  297.  
  298. 7. Signals
  299.  
  300. Wipeout watches for four signals that can be sent to it either by holding down
  301. the [Ctrl]-C/[Ctrl]-D/[Ctrl]-E keys or through the Shell "Break" command.
  302. These are:
  303.  
  304. [Ctrl]-C  Check and verify all active memory allocations
  305.  
  306. [Ctrl]-D  Disable Wipeout
  307.  
  308. [Ctrl]-E  Enable Wipeout
  309.  
  310.  
  311. 8. What is orphaned memory?
  312.  
  313. The Amiga does not yet know the concept of memory ownership. Memory allocated
  314. by one task may be passed to a different task; the original allocator may then
  315. safely exit. However, it sometimes happens that tasks allocate memory and exit
  316. before that memory is deallocated. Wipeout attempts to find out whether each
  317. task that allocated memory is still active. This helps to single out memory
  318. allocations that appear to belong to noone. Note that because allocations are
  319. associated with task addresses, Wipeout may not safely recognize orphaned
  320. allocations created by Shell programs. If you want to check whether a Shell
  321. program has left orphaned memory allocations behind, close the Shell window
  322. before entering "wipeout check" or use the Shell "Run" command to start the
  323. program you suspect will be losing memory.
  324.  
  325. If you intend to track orphaned memory and memory pools, make sure that you
  326. use the NAMETAG option.
  327.  
  328.  
  329. 9. How to watch for illegal memory usage?
  330.  
  331. Wipeout can help you to find out about illegal memory usage, such as trying to
  332. read from unallocated memory, to use uninitialized allocated memory or trying
  333. to execute code that was recently unloaded from memory. However, it cannot do
  334. this all by itself: "Enforcer" and "tnt" are required to report these
  335. problems. I thought about adding a feature to Wipeout which would fill memory
  336. with a code pattern which, if accidentally executed, would cause a routine
  337. inside Wipeout to be called. I did not add it since memory trashing could have
  338. interfered with the execution of this trigger code and because nobody could
  339. guarantee that an accidental jump into memory areas initialized like this
  340. would in fact hit the jump command. Enforcer is much better at tracking such
  341. problems; it will report all read/write accesses to addresses caused by memory
  342. munged by Wipeout and it can also track execution of commands at illegal
  343. addresses. "tnt" on the other hand is able to report where an illegal command
  344. was executed, such as in an area just munged by Wipeout.
  345.  
  346.  
  347. 10. What is in a Wipeout report?
  348.  
  349. Here is a sample Wipeout report with a few annotations:
  350.  
  351.    WIPEOUT HIT
  352. 1) 12-Apr-98 20:21:29
  353. 2) Front wall was stomped upon
  354. 3) Data: 00003039 FFFFFFFF 0000FFFF 00004E28 00000001 0000002B 0000003B 00003039
  355. 4) Addr: 0856B461 08568428 083E7714 084E58AD 084EF19C 08568428 08000848 085DC278
  356. 5) Stck: 0854ECEE 083E66D4 084E58B0 08000848 0854EF36 00000001 084E5940 0854EED8
  357.    Stck: 083E6678 00F94EC6 08000848 0854EBE6 084E58A0 083E7714 00004E20 00004E28
  358. 6) Name: "New_WShell"  CLI: "allocmemtest"  "allocmemtest" Hunk 0000 Offset 000002E2
  359.    ------------------------------------------------------------------------------
  360. 7) 0x08568428 = AllocMem(12345,...)
  361.    Created on 12-Apr-98 20:21:29
  362.            by task 0x083E6678, CLI program "allocmemtest"
  363.            at "allocmemtest" Hunk 0000 Offset 000002B6
  364.    ------------------------------------------------------------------------------
  365. 8) 1 byte(s) stomped (0x08568427..0x08568427), allocation-1 byte(s)
  366. 9) 08568427: 61...................................... a...................                  
  367.  
  368.  
  369. 1) This is the time and date of the Wipeout hit, i.e. the point of time when
  370.    an invalid memory management routine call was made.
  371.  
  372. 2) This indicates what type of problem occured; in this case memory preceding
  373.    the allocation was trashed.
  374.  
  375. 3) This is a dump of the MC68000 data registers
  376.  
  377. 4) This is a dump of the MC68000 address registers
  378.  
  379. 5) This is a dump of the stack active at the time the invalid memory
  380.    management routine call was made.
  381.  
  382. 6) This is the name of the task and the program name that made the call;
  383.    first the task name, then the CLI program name and the location of the
  384.    call in that program. In some cases, the CLI program name may be omitted
  385.    or the hunk/offset information may not be available.
  386.  
  387. 7) This is a short summary of the history of the memory allocation, stating
  388.    the size of the allocation, where it was allocated and who allocated it.
  389.  
  390. 8) This information is displayed in case memory was trashed. It tells you
  391.    how many bytes were trashed (in this case 1 byte), which byte is the
  392.    first and which is the last to take damage (in this case the first byte
  393.    to be damaged is located at address 0x08568427, the last one at address
  394.    0x08568427), and where the first trashed byte is located in relation to
  395.    the address of the allocation (in this case the last trashed byte
  396.    preceding the allocation is found one byte in front of the allocation
  397.    body). If the relative allocation address is positive, it indicates
  398.    where the first trashed byte to follow the allocation is found in
  399.    relation to the end of the allocation body.
  400.  
  401. 9) This information is displayed in case memory was trashed. It shows what
  402.    data the allocated memory wall was trashed with. Only trashed data will
  403.    be shown, both in a hexadecimal representation and, if possible, in ASCII
  404.    code (at the right hand side of the line).
  405.  
  406.  
  407. 11. Source code
  408.  
  409. For your convenience, the complete program source code is included in the
  410. distribution. Should you find bugs, make updates or enhancements, feel free to
  411. contact me. The source code was written for the SAS/C compiler.
  412.  
  413.  
  414. 12. API
  415.  
  416. In version 1.31 I added a humble API which allows you to control certain
  417. aspects of memory allocations made. In order to use it you need SAS/C or
  418. some glue code to make the call into the semaphore's control function
  419. possible (which accepts parameters in registers). The definitions are all
  420. in the 'pubwipeoutsemaphore.h' header file. Here is a small code snippet
  421. that changes the program counter associated with a memory allocation:
  422.  
  423.    #include "pubwipeoutsemaphore.h"
  424.  
  425.    ...
  426.  
  427.    void
  428.    change_pc(void *mem,unsigned long pc)
  429.    {
  430.       struct WipeoutSemaphore * ws;
  431.  
  432.       ws = (struct WipeoutSemaphore *)FindSemaphore(PUBWIPEOUTSEMAPHORENAME);
  433.       if(ws != NULL && ws->ws_Version >= PUBWIPEOUTSEMAPHOREVERSION)
  434.       {
  435.          struct TagItem tags[] =
  436.          {
  437.             { WOT_Address },
  438.             { WOT_SetPC },
  439.             { TAG_END }
  440.          };
  441.  
  442.          tags[0].ti_Data = mem;
  443.          tags[1].ti_Data = pc;
  444.  
  445.          (*ws->ws_ControlFunc)(tags);
  446.       }
  447.    }
  448.  
  449.  
  450. 13. Why Wipeout?
  451.  
  452. Too much surf music? No. I found MungWall needlessly cryptic to use; what are
  453. those "A: and C: addresses" anyway? And no matter what I did, MungWall always
  454. appeared to come up with the wrong options enabled. That and the fact that it
  455. could not track or detect errors in memory pool allocations made it a prime
  456. candidate for retirement. I had just written a program that used memory pools
  457. extensively and tracking possible bugs in it was no fun at all.
  458.  
  459.  
  460. 13. Author information
  461.  
  462. If you wish to contact me about Wipeout, you can use the following postal
  463. address:
  464.  
  465.    Olaf Barthel
  466.    Brabeckstrasse 35
  467.    D-30559 Hannover
  468.    Federal Republic of Germany
  469.  
  470. or you can use this e-mail address:
  471.  
  472.    olsen@sourcery.han.de
  473.  
  474.  
  475. 14. Release history
  476.  
  477. Wipeout 1.31 (6.2.2001)
  478.  
  479.     - Added a small API to the public semaphore.
  480.  
  481. Wipeout 1.30 (21.12.2000)
  482.  
  483.     - More fixes to the code that rounds the allocation pre- and
  484.       postsizes to multiples of eight bytes [Gunther Nikl].
  485.  
  486. Wipeout 1.29 (18.12.2000)
  487.  
  488.     - Memory allocations tagged with names are now properly aligned
  489.       to multiples of eight bytes, which helps 'Allocate()' and
  490.       'Deallocate()' [Gunther Nikl].
  491.  
  492.     - Allocation pre- and postsize are also rounded to be multiples
  493.       of eight bytes.
  494.  
  495. Wipeout 1.28 (7.10.99)
  496.  
  497.     - No longer tries to track allocations larger than 0x7FFFFFFF
  498.       bytes. This avoids an overflow error which can cause memory
  499.       allocations to succeed which should really fail.
  500.  
  501. Wipeout 1.27 (31.5.98)
  502.  
  503.     - All date stamps printed by the program were missing the extra,
  504.       separating space between time and date. I got caught by
  505.       irregularities introduced by the locale system. Now the date
  506.       and time conversion code strips off all heading/trailing spaces
  507.       before composing the string into a single line [Henrik Holst].
  508.  
  509. Wipeout 1.26 (31.5.98)
  510.  
  511.     - Changed the default options not to enforce the consistency
  512.       check. While this check does make sense, it introduces too
  513.       much overhead and slows the machine down. If you really need
  514.       it, better enable it manually.
  515.  
  516. Wipeout 1.25 (18.4.98)
  517.  
  518.     - Contrary to the documentation, the minimum number of stack lines
  519.       was not 0, but 1. Fixed.
  520.  
  521. Wipeout 1.24 (16.4.98)
  522.  
  523.     - Memory pools created were not tagged correctly.
  524.  
  525. Wipeout 1.23 (16.4.98)
  526.  
  527.     - Enhanced the NAMETAG option so that orphaned pools and
  528.       allocations are easier to recognize.
  529.  
  530. Wipeout 1.22 (16.4.98)
  531.  
  532.     - The consistency checks did not work out well due to the magic
  533.       header cookie getting reset for dead allocations. The code now
  534.       takes this into account.
  535.  
  536.     - When memory is released, not just the allocation body will be
  537.       trashed, the entire data structure including header and walls
  538.       will be filled with the memory munge pattern.
  539.  
  540.     - Releasing an entire memory pool now has the effect of trashing
  541.       every single allocation inside.
  542.  
  543. Wipeout 1.21 (14.4.98)
  544.  
  545.     - The MARK/UNMARK feature did change the memory marks, but forgot
  546.       to update the memory allocation checksum. Fixed.
  547.  
  548.     - Added the CONSISTENCECHECK/NOCONSISTENCECHECK options and the
  549.       corresponding functionality.
  550.  
  551. Wipeout 1.20 (13.4.98)
  552.  
  553.     - Initial public release
  554.